﻿using System.Data.SqlClient;
using ZilLion.Service.Core.ConfigManager.Manager;
using ZilLion.Service.Core.DapperWrapper;
using ZilLion.Service.Core.DapperWrapper.SqlServer;

namespace ZilLion.Service.TaskPlatform.Domain
{
    public class TaskRunnerSqlserverContext : DefaultContext, IDbContext
    {
        private readonly string _connectionString;

        public TaskRunnerSqlserverContext()
        {
            _connectionString =
                ZilLionConfigurationManager.GetConfigInstance<TaskManagerServiceConfig>().ConfigServerConn;
        }


        public override string ContextName => "TaskRunnerSqlserverContext";

        protected override string FomartConnectionString()
        {
            if (_connectionString.IsNullOrEmpty())
                return null;

            var appname = ContextName;
            var builder = new SqlConnectionStringBuilder(_connectionString)
            {
                ApplicationName = appname
            };
            return builder.ToString();
        }
    }
}